var base = null
var azurCtrl
var utils
var Keyboard
func _ready():
	pass
func _init():
	call_deferred("azurlineInit")
	pass
func _connect():
	pass

func azurlineInit():
	if globalData.infoDs.has("g_azurlaneBase"):
		base = globalData.infoDs["g_azurlaneBase"]
	if base != null:
		#初始化
		base.connect("onNewGame",self,"newGame")
		azurCtrl = globalData.infoDs["g_azurlane"]
		utils = globalData.infoDs["g_azurlaneUtils"]
		azurCtrl.connect("resetData", self, "resetData")

func resetData():
	window = null		

func newGame():
	pass

func afterTongGuan():
	var alertMsg = ""
	var achiChara = base.getSetting("achiChara", {})
	for i in sys.main.btChas:
		if i.team == 1 and not achiChara.has(i.ename):
			for j in i.items:
				if j.id == "i_ex_equip_ring" and j.num >= 15:
					var name = i.chaName.rsplit("」")[1].rsplit("·")[0]
					achiChara[i.ename] = name
					alertMsg += "成就：[color=#DC143C][真爱！%s][/color]已达成，可在控制面板-成就系统中查看\n"%name
					break	
	base.setSetting("achiChara", achiChara)
	if alertMsg != "":
		sys.newBaseMsg("通知", alertMsg)


var allArchiText = """
[color=#BDB76B][真爱！]：[/color]
条件：通关时，若有传奇角色佩戴誓约之戒后战斗超过15场，且在场上，则解锁该角色的真爱成就
奖励：解锁该角色的Live2D(若存在的话)，解锁该角色现代化改造的第二个选项
备注：通关81层BOSS战后会掉落一枚誓约之戒
"""

func showTotal():
	utils.openHelpWindow(allArchiText)	

var window
func open():
	if not is_instance_valid(window) or not window is WindowDialog:
		window = utils.createWindowDialog(sys.main.get_node("ui"), "成就系统", Vector2(1150, 600))
		var statisScroll = utils.createScrollContainer(window, Vector2(1070, 450), Vector2(30, 100))
		var context = utils.createVBox(statisScroll, Vector2(30, 30))
		var btn = utils.createItemButton(window, self, "成就总览", "showTotal")
		btn.rect_position = Vector2(50, 30)

		var achiChara = base.getSetting("achiChara", {})
		for i in achiChara.keys():
			var name = achiChara.get(i)
			utils.createRichTextLabel("[color=#DC143C][真爱！{name}][/color]：解锁该角色的Live2D(若存在的话)，解锁该角色现代化改造的第二个选项".format({"name":name}), context, Vector2(1000, 50))
	window.popup_centered()